﻿using System.Web;
using KingsSharp.Common.Web;

namespace CRM.Admin
{
    /// <summary>
    /// 顾客端帮助类
    /// </summary>
    public static class RequestExtended
    {
        /// <summary>
        /// 获取顾客端IP地址
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetIp(this HttpRequestBase request)
        {
            string ip = "";
            if (request.ServerVariables["HTTP_VIA"] != null) // using proxy 
            {
                ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP. 
            }
            else// not using proxy or can't get the Client IP 
            {
                ip = request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP. 
            }
            return ip;
        }
        /// <summary>
        /// 获取顾客端浏览器类型
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetBrowserName(this HttpRequestBase request)
        {
           return UserAgentHelper.GetBrowserName(request.UserAgent);
        }
        /// <summary>
        /// 获取顾客端操作系统名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static string GetSystemName(this HttpRequestBase request)
        {
            return UserAgentHelper.GetOperatingSystemName(request.UserAgent);
        }
    }
}